<?php

Class Test {

/**
* Function to test and handle input parameters to tasks
* @param array of parameters to be filled
* @param array of parameters sent to the api
* @param int 1 = required : 2 = required if not set use default : 3 = 1 or more required
* @param mixed default value
* @param array of allowed values 
* @return bool
*  ex: test_arg( array(&$data['output']), array($_REQUEST['output']), 2, 'json' );
*/

	function __construct() {
	}

	public function arg( $data, $request, $flag = 1, $default = '', $list = '') {
		switch ($flag) {
			case 1:
				for($i = 0; $i < count($request); $i++) {
					if(trim($request[$i]) != '') {
						if($list != '') {
							if(in_array(trim($request[$i]),$list)) {
								$data[$i] = trim($request[$i]);
								return true;
							} else {
								return false;
							}
						}
						$data[$i] = trim($request[$i]);
						return true;
					} else {
						return false;
					}
				}
				break;
			case 2:
				for($i = 0; $i < count($request); $i++) {
					if(trim($request[$i]) != '') {
						if($list != '') {
							if(in_array(trim($request[$i]),$list)) {
								$data[$i] = trim($request[$i]);
							} else {
								return false;
							}
						} else {
							$data[$i] = trim($request[$i]);
						}
					} else {
						$data[$i] = $default;
					}
					return true;
				}
				break;

			case 3:
				$j = false;
				for($i = 0; $i < count($request); $i++) {
					if(trim($request[$i]) != '') {
						$data[$i] = trim($request[$i]);
						$j = true;
					}
				}
					return $j;
				break;
		}
	}
}

?>
